package main

import (
	"os/exec"
	"os"
)

const (
	stringENTER = string(10)
	stringESC = string(27)
)

func cleanScreen() {
	os.Stdout.Write([]byte{0x1B, 0x5B, 0x33, 0x3B, 0x4A, 0x1B, 0x5B, 0x48, 0x1B, 0x5B, 0x32, 0x4A})
}

func getch() string {
	return string(getByte())
}

func getByte() byte {
	// disable input buffering
	exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run()
	// do not display entered characters on the screen
	exec.Command("stty", "-F", "/dev/tty", "-echo").Run()

	defer exec.Command("stty", "-F", "/dev/tty", "echo").Run()

	var b []byte = make([]byte, 1)
	os.Stdin.Read(b)

	return b[0]
}

func restoreGetByteEcho() {
	exec.Command("stty", "-F", "/dev/tty", "echo").Run()
}